<template>
  <div class="mainos">
    <div class="main_spac1 paddingBottom5">
      <div class="main_white padding10 paddingBottom20">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>查看入库单</span>
          </div>
          <el-popconfirm
            title="您确定导出当前入库单详情吗"
            @onConfirm="exportOrderiInfo"
          >
            <el-button slot="reference">导出</el-button>
          </el-popconfirm>
        </div>
        <div @click="mainor_ex = false">
          <div class="main_tile boxdq marginTop10">
            <div class="main_tile_l marginLeft0"><em></em>入库单详情</div>
          </div>
          <div class="main_xq">
            <ul class="boxha">
              <li>
                入库单号：<span>{{ info.order_sn }}</span>
              </li>
              <li>
                入库类型：<span>{{ base.typeList[info.type] }}</span>
              </li>
              <li>
                创建时间：<span>{{
                  parseTime(info.created_at, "{y}-{m}-{d}")
                }}</span>
              </li>
              <li>
                入库时间：<span>{{
                  parseTime(info.updated_at, "{y}-{m}-{d}")
                }}</span>
              </li>
              <li>
                入库状态：<span>{{ base.statusList[info.status] }}</span>
              </li>
              <li>
                入库金额：<span>{{ info.money }}</span>
              </li>
              <li>
                制单人：<span>{{ info.admin_user_name.name }}</span>
              </li>
              <li>
                关联单号：<span>{{ info.related_order_sn }}</span>
              </li>
              <li>
                采购类型：<span>{{ base.modeList[info.mode] }}</span>
              </li>
              <li>
                采购员/供应商：<span>{{
                  info.mode == 1
                    ? base.buyer[info.buyer_id]
                    : base.supplier[info.supplier_id]
                }}</span>
              </li>
              <li class="main_w100">
                备注：<span>{{ info.remark }}</span>
              </li>
            </ul>
          </div>
          <div class="main_tile boxdq marginTop10">
            <div class="main_tile_l marginLeft0"><em></em>商品详情</div>
            <div class="mainos_tile_r">合计：{{ total }}元</div>
          </div>
          <div class="main_table marginTop0">
            <el-table
              ref="multipleTable"
              v-loading="listLoading"
              :data="info.storage_list"
              element-loading-text="加载中"
              fit
              highlight-current-row
            >
              <el-table-column label="序号" prop="userId">
                <template slot-scope="scope">{{ scope.$index + 1 }}</template>
              </el-table-column>
              <el-table-column
                label="商品名称"
                width="150"
                prop="name"
                class-name="main_hei"
              >
                <template slot-scope="scope"
                  >{{ scope.row.goods.name }}【{{
                    scope.row.goods_spu.spu_name.title
                  }}】</template
                >
              </el-table-column>
              <el-table-column
                label="单位"
                prop="goods_spu.spu_unit.title"
                class-name="main_hei"
              />
              <el-table-column
                label="应入库数量"
                width="150"
                prop="num"
                class-name="main_hei"
              />
              <el-table-column
                label="实入库数量"
                width="150"
                prop="storage_num"
                class-name="main_hei"
              />
              <el-table-column
                label="单价"
                width="150"
                prop="price"
                class-name="main_hei"
              />
              <el-table-column
                label="入库金额"
                width="150"
                prop="money"
                class-name="main_hei"
              />
              <el-table-column
                label="备注"
                prop="remark"
                class-name="main_hei"
              />
            </el-table>
          </div>
          <div class="main_tile boxdq marginTop20">
            <div class="main_tile_l marginLeft0"><em></em>生命周期</div>
          </div>
          <div class="main_table marginTop0">
            <el-table
              ref="multipleTable"
              v-loading="listLoading"
              :data="info.logs"
              element-loading-text="加载中"
              fit
              highlight-current-row
            >
              <el-table-column
                label="管理员"
                prop="admin.name"
                class-name="main_hei"
              />
              <el-table-column
                label="操作"
                prop="operate.name"
                class-name="main_hei"
              />
              <el-table-column
                label="内容"
                prop="content"
                class-name="main_hei"
              >
                <template slot-scope="scope">
                  <div
                    v-for="(content, index) in scope.row.content"
                    :key="index"
                    class="marginTop5 marginBottom5"
                  >
                    {{ content }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="IP" prop="ip" class-name="main_hei" />
              <el-table-column
                label="时间"
                prop="created_at"
                class-name="main_hei"
              >
                <template slot-scope="scope">{{
                  parseTime(scope.row.created_at, "{y}-{m}-{d}")
                }}</template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  storage_base,
  storage_info,
  export_storage_info,
} from "@/api/warehouse/warehouseReceipt";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";

export default {
  computed: {
    total() {
      let sz = 0;
      this.info.storage_list.forEach((e) => {
        sz += parseFloat(e.num * e.price);
      });
      return sz.toFixed(2);
    },
  },
  components: {},
  data() {
    return {
      // 时间
      parseTime,
      // 基本信息
      info: {
        admin_user_name: {
          name: "",
        },
        created_at: "2000-01-01",
        updated_at: "2000-01-01",
        type: 0,
        status: 0,
        mode: 0,
        storage_list: [],
      },
      base: {
        modeList: ["后台"],
        statusList: ["后台"],
        buyer: ["后台"],
        supplier: ["后台"],
        typeList: ["待审核"],
      },
      listLoading: false,
      // id
      id: this.$route.params.id,
    };
  },
  created() {
    // 基本信息
    this.storage_info();
    this.storage_base();
  },
  methods: {
    // 基本信息
    storage_info() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      storage_info(data).then((res) => {
        if (res.errcode == 0) {
          this.info = res.data.info;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    storage_base() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name
      );
      storage_base(data).then((res) => {
        if (res.errcode == 0) {
          this.base = res.data;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 入库单详情导出
    exportOrderiInfo() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      export_storage_info(data)
        .then((res) => {
          const link = document.createElement("a");
          let blob = new Blob([res], { type: "application/vnd.ms-excel" });
          link.style.display = "none";
          link.href = URL.createObjectURL(blob);
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
        .catch(() => {
          this.$message.error("导出失败");
        });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainos {
  .main_tile {
    .mainos_tile_r {
      color: $colour_red;
      font-size: $font_14;
    }
  }
  .mainor_ex {
    position: fixed;
    width: 220px;
    height: 100%;
    background: $white;
    box-shadow: 0 6px 10px rgba(0, 21, 41, 0.08);
    top: 0;
    right: 0;
    z-index: 9999;
    transition: all 0.5s;
    transform: translate3d(100%, 0, 0);
    &.on {
      transform: translate3d(0, 0, 0);
    }
    .mainor_exb {
      position: absolute;
      width: 100%;
      height: calc(100% - 60px);
      overflow-y: auto;
      h3 {
        font-size: $font_16;
        color: $colour_18;
        height: 50px;
        line-height: 50px;
        border-bottom: 1px solid $colour_e6;
        padding-left: 20px;
      }
      .mainor_exb_an {
        padding-left: 20px;
        margin-top: 15px;
        /deep/.el-checkbox {
          display: block;
          margin-top: 15px;
          margin-bottom: 15px;
        }
      }
    }
    .mainor_exb_b {
      position: absolute;
      bottom: 0;
      width: 100%;
      border-top: 1px solid $colour_e6;
      height: 55px;
      text-align: center;
      /deep/.el-button--default {
        margin-top: 12px;
        border-color: $subActive;
        color: $menuText;
        &:hover {
          border-color: $menuActiveText;
          color: $menuActiveText;
        }
      }
    }
  }
}
</style>
